home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0071_VESA Video Support.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-26  |  9KB  |  267 lines

  1. Unit VESA;
  2.  
  3. Interface
  4.  
  5. Type ModeList=Array[1..32] Of Word;  { List of VESA mode numbers }
  6.  
  7.      TVesaMode=Record
  8.        Attr     : Word;         { Mode Attributes                   }
  9.        WinA     : Byte;         { Window A attributes               }
  10.        WinB     : Byte;         { Window B attributes               }
  11.        Gran     : Word;         { Window granularity in K bytes     }
  12.        WinSiz   : Word;         { Size of window in K bytes         }
  13.        SegA     : Word;         { Segment address of window A       }
  14.        SegB     : Word;         { Segment address of window B       }
  15.        WinFunc  : Procedure;    { Windows positioning function      }
  16.        Bytes    : Word;         { Number of bytes per line          }
  17.        Width    : Word;         { Number of horizontal pixels       }
  18.        Height   : Word;         { Number of vertical pixels         }
  19.        CharW    : Byte;         { Width of character cell           }
  20.        CharH    : Byte;         { Height of character cell          }
  21.        Planes   : Byte;         { Number of memory planes           }
  22.        Bits     : Byte;         { Number of bits per pixel          }
  23.        nBanks   : Byte;         { Number of banks        (not used) }
  24.        Model    : Byte;         { Memory model type                 }
  25.        Banks    : Byte;         { Size of bank           (not used) }
  26.        Pages    : Byte;         { Number of image pages             }
  27.        Reserved : Byte; { The following are for 15,16,24,32 bit colour modes }
  28.        RedMaskSize   : Byte;    { Size of Red mask in bits          }
  29.        RedFieldPos   : Byte;    { Bit position of LSB of Red mask   }
  30.        GreenMaskSize : Byte;    { Size of Green mask in bits        }
  31.        GreenFieldPos : Byte;    { Bit position of LSB of Green mask }
  32.        BlueMaskSize  : Byte;    { Size of Blue mask in bits         }
  33.        BlueFieldPos  : Byte;    { Bit position of LSB of Blue mask  }
  34.        RsvdMaskSize  : Byte;    { Size of Reserved mask in bits     }
  35.        RsvdFieldPos  : Byte;    { Bit pos. of LSB of Reserved mask  }
  36.        DirColModeInf : Byte;    { Direct Colour mode attributes     }
  37.        Filler   : Array[0..215] Of Byte; { Not used - filler        }
  38.      End;
  39.  
  40.      TVesaInfo=Record
  41.        Signature    : LongInt;   { Signature - "VESA"               }
  42.        Version      : Word;      { VESA Version number              }
  43.        OEMName      : PChar;     { Pointer to manufacturer name     }
  44.        Capabilities : Longint;   { Capabilities       (Not used)    }
  45.        List         : ^ModeList; { Pointer to list of VESA modes    }
  46.        TotalMemory  : Word;      { Number of 64k memory blocks on card }
  47.        Filler       : Array[1..238] of Byte;
  48.      End; { 258 byte size due to bug in the Diamond SpeedStar 24X v1.01 BIOS }
  49.  
  50.  
  51. Var  VesaMode : TVesaMode;
  52.                 { Contains all info needed for drawing on the screen }
  53.      VesaInfo : TVesaInfo;
  54.                 { Contains info on the VESA BIOS Extensions }
  55.  
  56.      vesaon   : Byte;
  57.                 { Specifies whether a VESA mode is on or not      }
  58.  
  59. Function  IsVesa:Boolean;
  60.           { Detects whether VESA support is present }
  61. Procedure GetVesaInfo;
  62.           { Get Information on VESA modes, etc }
  63. Procedure GetVesaModeInfo(md:Word);
  64.           { Get Information on a VESA mode (md) }
  65. Function  SetMode(md:Word):Boolean;
  66.           { Sets a video mode (OEM and VESA) }
  67. Function  GetMode:Word;
  68.           { Returns the current video mode }
  69. Function  SizeOfVideoState:Word;
  70.           { Returns the size of the buffer needed to save the video state }
  71. Procedure SaveVideoState(Var buf);
  72.           { Saves the SVGA video state in the buffer }
  73. Procedure RestoreVideoState(Var buf);
  74.           { Restores the SVGA video state from the buffer}
  75. Procedure SetBank(bank:Word);
  76.           { Set the video bank to draw on }
  77. Function  GetBank:Word;
  78.           { Gets the current active video bank }
  79. Procedure SetLineLength(Var len:Word);
  80.           { Sets the logical scan line length, returns the actual length set }
  81. Function  GetLineLength:Word;
  82.           { Returns the current logical scan line length }
  83. Procedure SetDisplayStart(pixel,line:Word);
  84.           { Sets the first pixel and line on the display }
  85. Procedure GetDisplayStart(Var pixel,line:Word);
  86.           { Returns the first pixel and line on the display }
  87.  
  88. {---------------------------------------------------------------------------}
  89. {-----------------------------} Implementation {----------------------------}
  90. {---------------------------------------------------------------------------}
  91.  
  92. Uses Dos;
  93.  
  94. Var  rp : Registers;
  95.  
  96. Function IsVesa:Boolean;
  97. Begin
  98.   rp.ax:=$4F03;
  99.   Intr($10,rp);
  100.   IsVesa:=(rp.al=$4F);
  101. End;
  102.  
  103. Procedure GetVesaInfo;
  104. Begin
  105.   rp.ax:=$4F00;
  106.   rp.di:=Ofs(VesaInfo);
  107.   rp.es:=Seg(VesaInfo);
  108.   Intr($10,rp);
  109. End;
  110.  
  111. Procedure GetVesaModeInfo(md:Word);
  112. Begin
  113.   rp.ax:=$4F01;
  114.   rp.cx:=md;
  115.   rp.di:=Ofs(VesaMode);
  116.   rp.es:=Seg(VesaMode);
  117.   Intr($10,rp);
  118. End;
  119.  
  120. Function SetMode(md:Word):Boolean;
  121. Begin
  122.   SetMode:=True; vesaon:=1;
  123.   If md>$FF Then Begin
  124.     rp.bx:=md;
  125.     rp.ax:=$4F02;
  126.     Intr($10,rp);
  127.     If rp.ax<>$4F Then SetMode:=False Else GetVesaModeInfo(md);
  128.   End Else Begin
  129.     rp.ax:=md;
  130.     Intr($10,rp);
  131.     VesaMode.Gran:=64; vesaon:=0;
  132.     VesaMode.SegA:=$A000;
  133.     Case md Of  { OEM (standard) video modes }
  134.       1..3,7 : Begin { Text modes }
  135.                  VesaMode.Width:=80;  VesaMode.Height:=25;
  136.                  If md=7 Then Begin
  137.                    VesaMode.Bits:=1;  VesaMode.SegA:=$B000;
  138.                  End Else Begin
  139.                    VesaMode.Bits:=4;  VesaMode.SegA:=$B800;
  140.                  End;
  141.                  VesaMode.Bytes:=160; VesaMode.Model:=0;
  142.                End;
  143.       $13 : Begin  { 320 x 200 x 256 colours, VGA & MCGA }
  144.               VesaMode.Width:=320; VesaMode.Height:=200;
  145.               VesaMode.Bits:=8;    VesaMode.Model:=4;
  146.               VesaMode.Bytes:=320;
  147.             End;
  148.       $12 : Begin  { 640 x 480 x 16 colours, VGA only }
  149.               VesaMode.Width:=640; VesaMode.Height:=480;
  150.               VesaMode.Bits:=4;    VesaMode.Model:=3;
  151.               VesaMode.Bytes:=80;
  152.             End;
  153.       $10 : Begin  { 640 x 350 x 16 colours, VGA & EGA with 128k+ }
  154.               VesaMode.Width:=640; VesaMode.Height:=350;
  155.               VesaMode.Bits:=4;    VesaMode.Model:=3;
  156.               VesaMode.Bytes:=80;
  157.             End;
  158.       $0E : Begin  { 640 x 200 x 16 colours, VGA & EGA }
  159.               VesaMode.Width:=640; VesaMode.Height:=200;
  160.               VesaMode.Bits:=4;    VesaMode.Model:=3;
  161.               VesaMode.Bytes:=80;
  162.             End;
  163.       $0D : Begin  { 320 x 200 x 16 colours, VGA & EGA }
  164.               VesaMode.Width:=320; VesaMode.Height:=200;
  165.               VesaMode.Bits:=4;    VesaMode.Model:=3;
  166.               VesaMode.Bytes:=40;
  167.             End;
  168.       Else SetMode:=False;
  169.     End;
  170.   End;
  171. End;
  172.  
  173. Function GetMode:Word;
  174. Begin
  175.   rp.ax:=$4F03;
  176.   Intr($10,rp);
  177.   GetMode:=rp.bx;
  178. End;
  179.  
  180. Function SizeOfVideoState:Word;
  181. Begin  { Will save/restore all video states }
  182.   rp.ax:=$4F04;
  183.   rp.dl:=0;
  184.   rp.cx:=$0F;  { hardware, BIOS, DAC & SVGA states }
  185.   Intr($10,rp);
  186.   SizeOfVideoState:=rp.bx;
  187. End;
  188.  
  189. Procedure SaveVideoState(Var buf);
  190. Begin
  191.   rp.ax:=$4F04;
  192.   rp.dl:=1;
  193.   rp.cx:=$0F;
  194.   rp.es:=Seg(buf);
  195.   rp.bx:=Ofs(buf);
  196.   Intr($10,rp);
  197. End;
  198.  
  199. Procedure RestoreVideoState(Var buf);
  200. Begin
  201.   rp.ax:=$4F04;
  202.   rp.dl:=2;
  203.   rp.cx:=$0F;
  204.   rp.es:=Seg(buf);
  205.   rp.bx:=Ofs(buf);
  206.   Intr($10,rp);
  207. End;
  208.  
  209. Procedure SetBank(bank:Word);
  210. Var winnum:Word;
  211. Begin
  212.   winnum:=bank*64 Div VesaMode.Gran;
  213.   rp.ax:=$4F05;
  214.   rp.bx:=0;
  215.   rp.dx:=winnum;
  216.   Intr($10,rp);
  217.   rp.ax:=$4F05;
  218.   rp.bx:=1;
  219.   rp.dx:=winnum;
  220.   Intr($10,rp);
  221. End;
  222.  
  223. Function GetBank:Word;
  224. Begin
  225.   rp.ax:=$4F05;
  226.   rp.bx:=$100;
  227.   Intr($10,rp);
  228.   GetBank:=rp.dx;
  229. End;
  230.  
  231. Procedure SetLineLength(Var len:Word);
  232. Begin
  233.   rp.ax:=$4F06;
  234.   rp.bl:=0;
  235.   rp.cx:=len;
  236.   Intr($10,rp); { dx:=maximum number of scan lines }
  237.   len:=rp.cx;
  238. End;
  239.  
  240. Function GetLineLength:Word;
  241. Begin
  242.   rp.ax:=$4F06;
  243.   rp.bl:=1;
  244.   Intr($10,rp); { dx:=maximum number of scan lines }
  245.   GetLineLength:=rp.cx;
  246. End;
  247.  
  248. Procedure SetDisplayStart(pixel,line:Word);
  249. Begin
  250.   rp.ax:=$4F07;
  251.   rp.bx:=0;
  252.   rp.cx:=pixel;
  253.   rp.dx:=line;
  254.   Intr($10,rp);
  255. End;
  256.  
  257. Procedure GetDisplayStart(Var pixel,line:Word);
  258. Begin
  259.   rp.ax:=$4F07;
  260.   rp.bx:=1;
  261.   Intr($10,rp);
  262.   pixel:=rp.cx;
  263.   line:=rp.dx;
  264. End;
  265.  
  266. End.
  267.